<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<form method="GET" id="form" onsubmit="formSubmit();afterSubmit(form);" target="target">
    <input type="text" id="textData" name="textData" value="a">
    <input type="submit" id="submitButton" name="submitform" value="Step">
</form>
<iframe id="target" name="target"></iframe>
<script>
description('Test that form.submit() when submitted from JS, form element added and removed, should submit the form without added element');

var hidden;
function formSubmit(event)
{
    var textData = document.getElementById('textData');
    var form = document.getElementById('form');
    var submit = document.getElementById('submitButton');
    textData.value = 'b';
    hidden = document.createElement('hidden');
    hidden.value = submit.value;
    hidden.name = submit.name;
    form.appendChild(hidden);
    form.submit();
    return true;
}

function afterSubmit(form)
{
    form.removeChild(hidden);
}

document.getElementById('target').onload = function(event) {
    shouldBeEqualToString('event.target.contentWindow.location.search', '?textData=b&submitform=Step');
    finishJSTest();
}

window.onload = function() {
    if (location.search == "")
        document.getElementById('submitButton').click();
}

if (window.testRunner)
    window.jsTestIsAsync = true;
</script>
</body>
</html>
